package com.wehaicao.wehaicaoshardingjdbc.test.controller;

import com.wehaicao.wehaicaoshardingjdbc.test.entity.Student;
import com.wehaicao.wehaicaoshardingjdbc.test.service.StudentService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.UUID;

@RestController
@RequestMapping("stu/")
@Slf4j
public class StudentController {

    @Autowired
    private StudentService studentService ;

    /**
     * 新增（这里懒得启动postman测试，直接写了个get方法）
     * @param name
     * @param age
     */
    @GetMapping("add")
    public void add(String name ,Integer age){
        Student student = new Student();
        student.setAge(age);
        student.setName(name);
        student.setId(UUID.randomUUID().toString());
        Student student1 = studentService.inserStudent(student);
        log.info("student info :{}",student1);
    }

    /**
     * 查询
     * @param id
     */
    @GetMapping("get")
    public void get(String id){
        Student student1 = studentService.getById(id);
        log.info("student info :{}",student1);
    }
}
